//
//  TFCameraViewManager.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/10.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit


class TFCameraViewManager: TFtouchesMoved {
    //视频窗口上的菊花
    @objc public var defaultDrawing1vN = UIButton()
    @objc public let tipLabel = UILabel()
    @objc public  lazy var activityIndicator:UIActivityIndicatorView = {

        if #available(iOS 13.0, *) {
            let act = UIActivityIndicatorView.init(style: UIActivityIndicatorView.Style.large)

            act.isUserInteractionEnabled = false

            return act
        }else
        {
            let act = UIActivityIndicatorView.init(style: UIActivityIndicatorView.Style.whiteLarge)

            act.isUserInteractionEnabled = false

            return act
        }
       
    }()
 
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //超出主层边框的都会被裁减调用
          //设置裁剪
//        self.layer.masksToBounds =  true
        // 圆角半径  能把一个下正文体,改成圆形
//        self.layer.cornerRadius = 4
        self.activityIndicator.isUserInteractionEnabled = false

        self.addSubview(self.activityIndicator)
        let button = UIButton(type: .custom)
        button.frame = CGRect(x: 0, y: 0, width: 114, height: 108)
        // 设置按钮的图片和文字
        button.setImage(UIImage(named: "HTLive.bundle/defaultDrawing1vN"), for: .normal)
        button.setTitle("老师暂未开启摄像头", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 9)
        button.setTitleColor(.white, for: .normal)
        
        // 设置按钮的图片和文字的位置
        //得到imageView和titleLabel的宽高
        let imageWidth = button.imageView?.frame.size.width
        let imageHeight = button.imageView?.frame.size.height
        
        var labelWidth: CGFloat! = 0.0
        var labelHeight: CGFloat! = 0.0
        
        labelWidth = button.titleLabel?.intrinsicContentSize.width
        labelHeight = button.titleLabel?.intrinsicContentSize.height
        
        //初始化imageEdgeInsets和labelEdgeInsets
        var imageEdgeInsets = UIEdgeInsets.zero
        var labelEdgeInsets = UIEdgeInsets.zero
        
        //根据style和space得到imageEdgeInsets和labelEdgeInsets的值
        imageEdgeInsets = UIEdgeInsets(top: -labelHeight-15/2, left: 0, bottom: 0, right: -labelWidth)
        labelEdgeInsets = UIEdgeInsets(top: 0, left: -imageWidth!, bottom: -imageHeight!-15/2, right: 0)
        button.isEnabled = false
        button.titleEdgeInsets = labelEdgeInsets
        button.imageEdgeInsets = imageEdgeInsets
        
        self.defaultDrawing1vN = button
        self.addSubview(self.defaultDrawing1vN)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.activityIndicator.frame  = self.bounds
        self.defaultDrawing1vN.frame = CGRect(x: (self.frame.size.width-144.0)/2.0, y: (self.frame.size.height-108)/2.0, width: 144.0, height: 108)
        
    }
   
}


